package com.ywdnf.gomoku.model.chess;

import lombok.Getter;
import lombok.Setter;

/**
 * 回合模型
 *
 * @author lss
 * @date 2019-06-26, Wed
 */
@Getter
@Setter
public class Round {

  /**
   * 次序，第几回合
   */
  private int sequence;

  /**
   * 先手玩家的步数
   */
  private int p1StepCount;

  private int p2StepCount;

  /**
   * 获胜玩家
   */
  private Player winner;

  /**
   * 先手玩家
   */
  private Player first;

  /**
   * 当前状态的棋盘布局
   */
  private GomokuLayout curLayout;

  /**
   * 是否游戏结束
   */
  private boolean finish;

  /**
   * 当前落子的玩家
   */
  private Player curOptPlayer;

  public Round() {
    curLayout = new GomokuLayout();
  }

  /**
   * 当前操作用户步数增加
   */
  public void addOptPlayerStep() {
    if (curOptPlayer == null || first == null) {
      return;
    }
    if (curOptPlayer.equals(first)) {
      p1StepCount++;
    } else {
      p2StepCount++;
    }
  }

  public int getPlayerStepCount(Player p) {
    if (p == null) {
      return 0;
    }
    return p.equals(first) ? p1StepCount : p2StepCount;
  }

  public void setWinner(Player winner) {
    this.winner = winner;
    winner.winAndIncreaseIntegral();
  }
}
